package com.pubinfo.passbook.engine.cell.logic.medicine;

import com.pubinfo.passbook.common.entity.TPassbook;
import com.pubinfo.passbook.common.mapper.TSubsidiaryInfoMapper;
import com.pubinfo.passbook.common.model.bo.witeoff.CityInfo;
import com.pubinfo.passbook.common.model.dto.witeoff.MedicineOnJobOrRetireDTO;
import com.pubinfo.passbook.common.service.master.TPassbookService;
import com.pubinfo.passbook.common.service.ruler.CheckService;
import com.pubinfo.passbook.engine.utils.ApplicationContextUilts;

import java.math.BigDecimal;

/**
 * 是否特殊用户
 *
 * @author zhouch
 * @date 2022/1/10 11:40
 */
public class SpecialUserUnit extends MedicineLogicUnit {

    TPassbookService passbookService;

    TSubsidiaryInfoMapper infoMapper;

    CheckService ruleService;

    public SpecialUserUnit() {
        passbookService = ApplicationContextUilts.getBean(TPassbookService.class);
        infoMapper = ApplicationContextUilts.getBean(TSubsidiaryInfoMapper.class);
        ruleService = ApplicationContextUilts.getBean(CheckService.class);
    }

    @Override
    public Boolean then(MedicineOnJobOrRetireDTO data, BigDecimal result) {
        TPassbook passbook = passbookService.getPassbookById(data.getInvoiceIds()).get(0);
        // 报账人身份证号码
        String idNo = passbook.getPayerPartyCode();
        CityInfo info = infoMapper.findCityInfoByNsrsbh(passbook.getNsrsbh());

        return ruleService.isSpecialUser(info.getDistrictName(), idNo);
    }

    @Override
    public String getName() {
        return "是否特殊用户";
    }
}
